package com.slj.spring_security_demo.controller;



import com.slj.spring_security_demo.entity.UserEntity;
import com.slj.spring_security_demo.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserController {
    @Resource
    private UserService userService;

    @PostMapping("")
    public void save(@RequestBody UserEntity user) {
        userService.save(user);
    }

    @GetMapping("/users")
    public List<UserEntity> findAll() {
        return userService.findAll();
    }

    @PreAuthorize("hasRole('admin')")
    @GetMapping("/users/{id}")
    public UserEntity findById(@PathVariable("id") Long id) {
        return new UserEntity();
    }
}
